package com.ruoyi.web.controller.check;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.check.domain.MyTable;
import com.ruoyi.check.service.IMyTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * xxxxxxxxController
 *
 * @author hugh.sun
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/check/table")
public class MyTableController extends BaseController
{
    @Autowired
    private IMyTableService myTableService;
    /**
     * 查询xxxxxxxx列表
     */
    @PreAuthorize("@ss.hasPermi('check:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyTable myTable)
    {
        startPage();
        List<MyTable> list = myTableService.selectMyTableList(myTable);
        return getDataTable(list);
    }

    @GetMapping("/list1")
    public void list1()
    {
        //判断id
        try{
        Long copysql = myTableService.copysql();
        if(copysql>=500000L){
            //拷贝表
            Date date = new Date();
            SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyyMMdd");
            //拷贝表
            String format = yyyyMMdd.format(date);

            myTableService.copybiao(format);
            //拷贝完成截断表
            myTableService.jieduan();
        }}catch (Exception e){
        }

    }



    /**
     * 导出xxxxxxxx列表
     */
    @PreAuthorize("@ss.hasPermi('check:table:export')")
    @Log(title = "xxxxxxxx", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyTable myTable)
    {
        List<MyTable> list = myTableService.selectMyTableList(myTable);
        ExcelUtil<MyTable> util = new ExcelUtil<MyTable>(MyTable.class);
        util.exportExcel(response, list, "xxxxxxxx数据");
    }

    /**
     * 获取xxxxxxxx详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:table:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myTableService.selectMyTableById(id));
    }

    /**
     * 新增xxxxxxxx
     */
    @PreAuthorize("@ss.hasPermi('check:table:add')")
    @Log(title = "xxxxxxxx", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyTable myTable)
    {
        return toAjax(myTableService.insertMyTable(myTable));
    }

    /**
     * 修改xxxxxxxx
     */
    @PreAuthorize("@ss.hasPermi('check:table:edit')")
    @Log(title = "xxxxxxxx", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyTable myTable)
    {
        return toAjax(myTableService.updateMyTable(myTable));
    }

    /**
     * 删除xxxxxxxx
     */
    @PreAuthorize("@ss.hasPermi('check:table:remove')")
    @Log(title = "xxxxxxxx", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myTableService.deleteMyTableByIds(ids));
    }
}
